package pegpeg.client;

import com.google.gwt.canvas.dom.client.Context2d;

public class Peg {
	public int row, col;
	public double posX, posY;
	public String color, darkc;
	public boolean hasPeg;
	public boolean dark;
    public int radius = 15;

	public Peg(Peg another){
		this.row = another.row;
		this.col = another.col;
		this.posX = another.posX;
		this.posY = another.posY;
		this.color = another.color;
		this.darkc = another.darkc;
		this.hasPeg = another.hasPeg;
		this.dark = false;
	}
	
	public Peg(int i, int j, double px, double py, String color, String darkc) {
		this.row = i;
		this.col = j;
		this.color = color;
		this.darkc = darkc;
		this.posX = px;
		this.posY = py;
		this.hasPeg = true;
		this.dark = false;
	}
	
	public void draw(Context2d context) {
		if (this.hasPeg) {
			if (this.dark)
				context.setFillStyle(darkc);
			else 
				context.setFillStyle(color);
			
			context.save();
			context.beginPath();
			context.arc(posX, posY, radius, 0, Math.PI * 2.0, true);
			context.closePath();
			context.setShadowColor("#bbbbbb");
			context.setShadowBlur(10);
			context.setShadowOffsetX(15);
			context.setShadowOffsetY (15);
			context.fill();
			
			if (this.dark) {
				context.setLineWidth(0.2*radius);
				context.setStrokeStyle ("black");
				context.stroke();
			}
			context.restore();
		} else {
			context.setFillStyle("#808080");
			context.beginPath();
			context.arc(posX, posY, radius/2, 0, Math.PI * 2.0, true);
			context.closePath();
			context.fill();
		}
	}
	
	public boolean check(int mouseX, int mouseY) {
		double xx = mouseX-this.posX;
		double yy = mouseY-this.posY;
		if (xx*xx+yy*yy > radius*radius)
			return false;
		return true;
	}
}
